package com.cleaningcloud.erp.api.factory;

import com.cleaningcloud.common.core.domain.R;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.erp.api.RemoteWareService;
import com.cleaningcloud.erp.api.domain.ErpWareCommodityNumber;
import com.cleaningcloud.erp.api.domain.ErpWareHouse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RemoteWareFallbackFactory implements FallbackFactory<RemoteWareService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteWareFallbackFactory.class);

    @Override
    public RemoteWareService create(Throwable throwable) {
        log.error("进销存仓库管理服务调用失败:{}", throwable.getMessage());
        return new RemoteWareService() {
            @Override
            public AjaxResult addWare(ErpWareHouse wareHouse, String source) {
                return AjaxResult.error("新增仓库信息失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult updateWareNameByPostId(ErpWareHouse wareHouse, String source) {
                return AjaxResult.error("修改仓库名称失败:" + throwable.getMessage());
            }


            @Override
            public AjaxResult closureWareHouse(Long projectId, String source) {
                return AjaxResult.error("关闭项目仓及岗位仓失败:" + throwable.getMessage());
            }

            @Override
            public ErpWareHouse getWareHouseByProjectId(Long projectId, String source) {
                return null;
            }

            @Override
            public ErpWareHouse getWareHouseByPostId(Long postId, String source) {
                return null;
            }

            @Override
            public R<Boolean> batchAddWare(List<ErpWareHouse> list, String source) {
                return R.fail("批量信息仓库信息失败:" + throwable.getMessage());
            }

            @Override
            public ErpWareCommodityNumber selectByCommodityIdAndWareId(ErpWareCommodityNumber erpWareCommodityNumber, String source) {
                return null;
            }

            @Override
            public R<Boolean> updateErpWareCommodityNumber(ErpWareCommodityNumber erpWareCommodityNumber, String source) {
                return R.fail("修改仓库库存失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> insertErpWareCommodityNumber(ErpWareCommodityNumber erpWareCommodityNumber, String source) {
                return R.fail("新增仓库库存失败:" + throwable.getMessage());
            }


        };
    }
}
